
package com.tool.tcpimg;

import com.tool.image.ImageMixDeal;
import com.tool.image.ManimgAttribute;
import com.tool.tcp.Frame;
import com.tool.tcp.GetTcpPath;
import com.tool.tcp.Sprite;
import com.tool.tcp.SpriteFactory;
import java.awt.Dimension;
import java.awt.Graphics;
import java.util.ArrayList;
import org.come.until.ScrenceUntil;
//TODO 顶部特效滚动条，滚动消息
public class SystemBox
{

	private RichLabel text;
	private int length;
	private int value;
	private int height;
	private java.util.List line;
	private Sprite tcp;
	private String skin;

	public SystemBox(String text, String skin)
	{
		this.skin = skin;
		CZ(text);
	}

	public void draw(Graphics g)
	{
		if (text == null) {
            return;
        }
		value++;
		if (value < length)
		{
			//Graphics g2 = g.create(0, ScrenceUntil.Screen_y - 690, ScrenceUntil.Screen_x, 60);
			Graphics g2 = g.create(0, ScrenceUntil.Screen_y -720, ScrenceUntil.Screen_x, 60);
		//	Graphics g2 = g.create(-1, ScrenceUntil.Screen_y - 770, ScrenceUntil.Screen_x, 770);
			if (tcp == null)
			{
				tcp = SpriteFactory.Prepare(GetTcpPath.getMouseTcp(skin));
			} else
			{
				tcp.updateToTime(ImageMixDeal.userimg.getTime(), 0);
				Frame frame = tcp.getCurrFrame();
				if (frame != null && frame.getImage() != null) {
                    g2.drawImage(frame.getImage(), 2 - frame.getRefPixelX(), 2 - frame.getRefPixelY(), ScrenceUntil.Screen_x, frame.getHeight(), null);
                }
			}
			g2.translate(ScrenceUntil.Screen_x - value, height);
			text.paint(g2);
			g2.dispose();
		} else
		{
			CZ(null);
		}
	}

	public void addText(String text)
	{
		if (this.text == null)
		{
			CZ(text);
		} else
		{
			if (line == null) {
                line = new ArrayList();
            }
			line.add(text);
		}
	}

	public void CZ(String text)
	{
		if (text == null)
		{
			if (line != null && line.size() != 0) {
                text = (String)line.remove(0);
            }
		} else
		if (line != null) {
            line.remove(text);
        }
		if (text == null)
		{
			tcp = null;
			this.text = null;
			return;
		}
		if (this.text == null) {
            this.text = new RichLabel(text, UIUtils.TEXT_NAME_FONT, 9999);
        } else {
            this.text.setTextSize(text, 9999);
        }
		length = ScrenceUntil.Screen_x + this.text.getWidth();
		value = 0;
		height = (int)(38D - this.text.getSize().getHeight());
	}
}
